import request from '@/utils/request'

// 获取帖子列表
export function getPosts(query) {
  return request({
    url: '/posts',
    method: 'get',
    params: query
  })
}

// 获取帖子详情
export function getPostDetail(id) {
  return request({
    url: `/posts/${id}`,
    method: 'get'
  })
}

// 发布帖子
export function publishPost(data) {
  return request({
    url: '/posts',
    method: 'post',
    data
  })
}

// 获取热门帖子
export function getHotPosts(limit = 10) {
  return request({
    url: '/posts/hot',
    method: 'get',
    params: { limit }
  })
}

// 点赞/取消点赞帖子
export function toggleLike(postId) {
  return request({
    url: `/posts/${postId}/like`,
    method: 'post'
  })
}

// 检查是否点赞
export function checkLike(postId) {
  return request({
    url: `/posts/${postId}/like`,
    method: 'get'
  })
}

// 获取帖子点赞数
export function getLikeCount(postId) {
  return request({
    url: `/posts/${postId}/like/count`,
    method: 'get'
  })
}

// 删除帖子（管理员）
export function deletePost(id) {
  return request({
    url: `/admin/posts/${id}`,
    method: 'delete'
  })
}

// 获取精华帖子列表
export function getFeaturedPosts(query) {
  return request({
    url: '/posts/featured',
    method: 'get',
    params: query
  })
}

// 获取用户帖子列表
export function getUserPosts(userId, query) {
  return request({
    url: `/posts/user/${userId}`,
    method: 'get',
    params: query
  })
}

// 设置/取消精华帖子
export function setFeaturedPost(id, isFeatured) {
  return request({
    url: `/admin/posts/${id}/featured`,
    method: 'put',
    params: { isFeatured }
  })
}
